local zhanyue = fk.CreateSkill {
    name = "jlspgod__zhanyue",
}

zhanyue:addEffect(fk.TargetSpecified, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(zhanyue.name) and data.card.trueName == "slash"
      and data:isOnlyTarget(data.to) and not data.to.dead and not (data.card.extra_data and data.card.extra_data.zhanyue)--不能重复指定
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if player.room:askToSkillInvoke(player, {
            skill_name = self.name,
            prompt = "#jlspgod__zhanyue-invoke",
          }) then

            local success, dat = room:askToUseActiveSkill(player, {
                skill_name = "jlspgod__zhanyue_targets",
                cancelable = true,
                extra_data = {
                  zhanyue_taregt = data.to.id,
                }
              })
            if success and dat then
                event:setCostData(self, {additional_targets = dat.targets})
     
            end
            return true
            
        end
        

        
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cost_data = event:getCostData(self)
        if cost_data and cost_data.additional_targets and #cost_data.additional_targets > 0 then
            for _, p in ipairs(cost_data.additional_targets) do
                data:addTarget(p)
            end
        end
        data.use.extraUse=true--不计入次数限制
      player:addCardUseHistory(data.card.trueName, -1)

        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if use_event == nil then return end
        --无视防具
        for _,p in ipairs(data:getAllTargets()) do
   
            room:setPlayerMark(p, MarkEnum.MarkArmorNullified, 1)
        end
        use_event:addCleaner(function()
            for _,p in ipairs(data:getAllTargets()) do
                room:removePlayerMark(p, MarkEnum.MarkArmorNullified)
            end
        end)
        data.use.extra_data=data.use.extra_data or {}
        data.use.extra_data.zhanyue = true
        data.card.extra_data=data.card.extra_data or {}
        data.card.extra_data.zhanyue = true
    end,
})

--造成伤害增加
zhanyue:addEffect(fk.DamageCaused, {
    mute=true,
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(self.name) and target==player and data.card and data.card.trueName == "slash"  then
            
            return data.card.extra_data and data.card.extra_data.zhanyue
        
        end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local damage=(data.to.hp+1)//2
        damage=damage-data.damage
        if damage>0 then
            data:changeDamage(damage)
        end
    end,
})

-- 杀结算后摸牌
zhanyue:addEffect(fk.CardUseFinished, {
    mute=true,
    can_trigger = function(self, event, target, player, data)

        return player:hasSkill(self.name) and data.card and data.card.trueName == "slash" 
        and data.card.extra_data and data.card.extra_data.zhanyue and data.damageDealt
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        
        local damage_count = 0
        for _,p in ipairs(data:getAllTargets()) do
            damage_count = damage_count + (data.damageDealt[p] or 0)
        end
        player:drawCards(damage_count, self.name)
        data.card.extra_data.zhanyue = nil
    end,
})

Fk:loadTranslationTable{
    ["jlspgod__zhanyue"] = "斩月",
    [":jlspgod__zhanyue"] = [[当你使用【杀】仅指定一名其他角色为目标后，你可以令至多两名与其相连的其他角色也成为目标，
    然后令此【杀】无视防具、不计入次数限制目造成目标一半体力的伤害，此【杀】结算后，你摸此【杀】造成伤害总数的牌。]],
    ["#jlspgod__zhanyue"] = "斩月：你可以选择至多两名与目标相邻的其他角色，令他们也成为此【杀】的目标",
    ["$jlspgod__zhanyue1"]="刀光所至，万军辟易。尔等凡躯，岂堪神锋！",
    ["$jlspgod__zhanyue2"]="桃园一诺。忠义不负。此刃既出。天地同戮！",
    ["#jlspgod__zhanyue-invoke"]="斩月：你可以令至多两名与目标相邻的其他角色，令他们也成为此【杀】的目标,然后强化杀",
}

return zhanyue 